<template>
    <div class="app-container">
        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
            <el-form-item label="EmployeeID" prop="employeeId">
                <el-input
                    v-model="queryParams.employeeId"
                    placeholder="请输入EmployeeID"
                    clearable
                    @keyup.enter.native="handleQuery"
                />
            </el-form-item>
            <el-form-item label="Name" prop="name">
                <el-input
                    v-model="queryParams.name"
                    placeholder="请输入Name"
                    clearable
                    @keyup.enter.native="handleQuery"
                />
            </el-form-item>
            <el-form-item label="Dept." prop="deptId">
                <el-select v-model="queryParams.deptId" style="width:150px" placeholder="Select Dept."
                           clearable>
                    <el-option
                        v-for="item in deptList "
                        :key="item.deptId"
                        :label="item.deptName"
                        :value="item.deptId"
                    />
                </el-select>
            </el-form-item>
            <el-form-item label="FileName" prop="fileName">
                <el-input
                    v-model="queryParams.fileName"
                    placeholder="请输入FileName"
                    clearable
                    @keyup.enter.native="handleQuery"
                />
            </el-form-item>
            <el-form-item>
                <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form>

        <el-row :gutter="10" class="mb8">
            <el-col :span="1.5">
                <el-button
                    type="warning"
                    plain
                    icon="el-icon-download"
                    size="mini"
                    @click="handleExport"
                    v-hasPermi="['business:verb:export']"
                >导出</el-button>
            </el-col>
            <right-toolbar :showSearch.sync="showSearch" @queryTable="getGroupList"></right-toolbar>
        </el-row>

        <el-table v-loading="loading" :data="verbList" @selection-change="handleSelectionChange">
<!--            <el-table-column type="selection" width="55" align="center" />
            <el-table-column label="No." align="center" prop="id" />-->
            <el-table-column label="EmployeeID" align="center" prop="employeeId" />
            <el-table-column label="Name" align="center" prop="name" />
            <el-table-column label="DeptName" align="center" prop="deptName" />
            <el-table-column label="FileName" align="center" prop="fileName" >
                <template slot-scope="scope">
                    {{ getFileName(scope.row.fileName) }}
                </template>
            </el-table-column>
            <el-table-column label="FirstTime" align="center" prop="firstTime" width="180">
                <template slot-scope="scope">
                    <span>{{ parseTime(scope.row.firstTime) }}</span>
                </template>
            </el-table-column>
            <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
                <template slot-scope="scope">
                    <el-button @click="viewDetails(scope.row)" type="text">详细信息</el-button>
                </template>
            </el-table-column>
            <!--            <el-table-column label="ReadStatus" align="center" prop="readStatus">
                            <template slot-scope="scope">
                                <dict-tag :options="dict.type.file_read_status" :value="scope.row.readStatus"/>
                            </template>
                        </el-table-column>-->
            <!--            <el-table-column label="ReadTime" align="center" prop="readTime" width="180">
                            <template slot-scope="scope">
                                <span>{{ parseTime(scope.row.readTime) }}</span>
                            </template>
                        </el-table-column>-->
            <!--            <el-table-column label="操作" align="center" class-name="small-padding fixed-width">-->
            <!--                -->
            <!--            </el-table-column>-->
        </el-table>
        <el-dialog title="详细信息" :visible.sync="detailOpen">
            <el-table :data="detailListData">
                <el-table-column label="EmployeeID" align="center" prop="employeeId" />
                <el-table-column label="Name" align="center" prop="name" />
                <el-table-column label="DeptName" align="center" prop="deptName" />
                <el-table-column label="FileName" align="center" prop="fileName" >
                    <template slot-scope="scope">
                        {{ getFileName(scope.row.fileName) }}
                    </template>
                </el-table-column>
                <el-table-column label="ReadTime" align="center" prop="readTime" width="180">
                    <template slot-scope="scope">
                        <span>{{ parseTime(scope.row.readTime) }}</span>
                    </template>
                </el-table-column>
            </el-table>

            <pagination
                v-show="detailtotal>0"
                :total="detailtotal"
                :page.sync="detailqueryParams.pageNum"
                :limit.sync="detailqueryParams.pageSize"
                @pagination="getList(null)"
            />
        </el-dialog>
        <pagination
            v-show="total>0"
            :total="total"
            :page.sync="queryParams.pageNum"
            :limit.sync="queryParams.pageSize"
            @pagination="getGroupList"
        />
    </div>
</template>

<script>
import { listVerb, getVerb, listGroupVerb} from "@/api/business/verb";
import {getDeptList} from "@/api/business/goodCatch";

export default {
    name: "Verb",
    /*dicts: ['file_read_status'],*/
    data() {
        return {
            // 遮罩层
            loading: true,
            // 选中数组
            ids: [],
            // 非单个禁用
            single: true,
            // 非多个禁用
            multiple: true,
            // 显示搜索条件
            showSearch: true,
            // 总条数
            total: 0,
            // 文件浏览表格数据
            verbList: [],
            // 弹出层标题
            title: "",
            // 是否显示弹出层
            open: false,
            deptList: [],
            // 查询参数
            queryParams: {
                pageNum: 1,
                pageSize: 10,
                employeeId: null,
                name: null,
                deptName: null,
                fileName: null,
            },
            detailQueryParams:{
                pageNum: 1,
                pageSize: 10,
                employeeId: null,
                name: null,
                deptName: null,
                fileName: null,
            },
            // 表单参数
            form: {},
            // 表单校验
            rules: {
            },
            detailTotal:0,
            detailListData:[],
            detailOpen:false
        };
    },
    created() {
        this.getGroupList();
        this.getDeptList();
    },
    methods: {
        /** 查询文件浏览列表 */
        getGroupList() {
            this.loading = true;
            listGroupVerb(this.queryParams).then(response => {
                this.verbList = response.rows;
                this.total = response.total;
                this.loading = false;
            });
        },
        getList(row){
            if(row){
                this.detailQueryParams.employeeId = row.employeeId
                this.detailQueryParams.filePath = row.filePath
            }
            console.log(this.detailQueryParams)
            listVerb(this.detailQueryParams).then(response =>{
                console.log(response)
                this.detailListData = response.rows;
                console.log(this.detailListData)
                this.detailTotal = response.total;
            });
            this.detailOpen = true

        },
        getFileName(fileName) {
            if (fileName) {
                const fileNameList = fileName.split("\\");
                return fileNameList[fileNameList.length - 1];
            }
            return ''
        },
        viewDetails(row){
            this.getList(row)
        },
        // 取消按钮
        cancel() {
            this.open = false;
            this.reset();
        },
        // 表单重置
        reset() {
            this.form = {
                id: null,
                no: null,
                employeeId: null,
                name: null,
                deptId: null,
                deptName: null,
                fileName: null,
                readStatus: null,
                readTime: null
            };
            this.resetForm("form");
        },
        getDeptList() {
            getDeptList().then(res => {
                this.deptList = res.data
                const userDeptId = this.user.deptId
                const userDept = this.deptList.find(item => item.deptId === userDeptId)
                this.userDeptOwner = userDept.owner
                const ownerMessage =  {'value': userDept.owner, "userId": null, "deptId": userDeptId}
                this.userNameList.push(ownerMessage)

            })
        },
        /** 搜索按钮操作 */
        handleQuery() {
            this.queryParams.pageNum = 1;
            this.getGroupList();
        },
        /** 重置按钮操作 */
        resetQuery() {
            this.resetForm("queryForm");
            this.handleQuery();
        },
        // 多选框选中数据
        handleSelectionChange(selection) {
            this.ids = selection.map(item => item.id)
            this.single = selection.length!==1
            this.multiple = !selection.length
        },
        /** 导出按钮操作 */
        handleExport() {
            this.download('bussiness/verb/export', {
                ...this.queryParams
            }, `verb_${new Date().getTime()}.xlsx`)
        }
    }
};
</script>
